package com.op.crm.ui.tags;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.op.crm.persist.model.Role;
import com.op.crm.persist.model.User;

@SuppressWarnings("serial")
public class PermissionTag extends TagSupport{

	private String required = null;
	
	public String getRequired() {
		return required;
	}

	public void setRequired(String required) {
		this.required = required;
	}

	@Override
	public int doStartTag() throws JspException {
		
		User user = (User)pageContext.getSession().getAttribute("crm_user");
		if (user != null) {
			for (Role r : user.getRoles()) {
				if (r.getRoleId().equals(this.required)) {
					return EVAL_BODY_INCLUDE;
				}
			}
		}
		return SKIP_BODY;
	}
	
	@Override
	public int doEndTag() throws JspException {
		return EVAL_PAGE;
	}
}
